package com.mjk.promethues;

import com.mjk.common.core.prometheus.annotation.BeeMetric;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import org.apache.http.pool.PoolStats;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 自定义指标添加
 */
@BeeMetric
public class CustemCollector extends Collector {
    private static final List<String> LABEL_NAMES = Collections.singletonList("custom");

    private final Map<String, PoolStats> poolStatsMap = new ConcurrentHashMap();
    @Override
    public List<MetricFamilySamples> collect() {
        return Arrays.asList(this.createGauge("custom_number", "custom", 3));
    }

    private GaugeMetricFamily createGauge(String metric, String help, int value) {
        GaugeMetricFamily metricFamily = new GaugeMetricFamily(metric, help, LABEL_NAMES);

        metricFamily.addMetric(Arrays.asList(new String[]{"total"}), (double) value);

        return metricFamily;
    }
}
